package com.sky.mapper;

import com.sky.dto.GoodsSalesDTO;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface ReportMapper {
    /**
     * 查询完成订单数量
     * @param map
     * @return
     */
    @Select("select sum(amount) from orders where status = #{status} and order_time between #{begin} and #{end}")
    Integer turnoverStatistics(Map map);

    /**
     * 查询新增用户
     * @param map
     * @return
     */
    @Select("select count(*) from user where create_time between #{begin} and #{end}")
    Integer newUser(Map map);

    /**
     * 查询所有用户
     * @param map
     * @return
     */
    @Select("select count(*) from user where create_time <= #{end}")
    Integer allUser(Map map);

    /**
     * 每日订单数
     * @param map
     * @return
     */
    @Select("select count(*) from orders where order_time between #{begin} and #{end}")
    Integer orderCountList(Map map);

    /**
     * 查询每日有效订单数
     * @param map
     * @return
     */
    @Select("select count(*) from orders where order_time between #{begin} and #{end} and status = #{status}")
    Integer validOrderCountList(Map map);
    @Select("select name,sum(od.number) number\n" +
            "from orders o,order_detail od\n" +
            "where o.id = od.order_id\n" +
            "  and o.status = 5\n" +
            "   and order_time between #{begin}\n" +
            "   and #{end}\n" +
            "group by name\n" +
            "order by number desc\n" +
            "limit 0,10")
    List<GoodsSalesDTO> top10(Map map);
}
